<%--
  Created by IntelliJ IDEA.
  User: ykq
  Date: 2022/10/10
  Time: 11:01
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>登录界面</title>
    <!--引入elementui得样式-->
    <link type="text/css" rel="stylesheet" href="/css/index.css"/>
    <!--引入vue得依赖必须再elementui之前引入vue-->
    <script type="text/javascript" src="/js/vue.js"></script>
    <script type="text/javascript" src="/js/index.js"></script>
    <script type="text/javascript" src="/js/axios.min.js"></script>
    <script type="text/javascript" src="/js/qs.min.js"></script>
</head>
<body>
    <div id="login">
        <div id="loginBox">
            <el-form :model="loginForm" status-icon :rules="loginRules" ref="ruleForm"  label-width="80px" class="demo-ruleForm" id="loginForm">
                <el-form-item label="账号:" prop="username">
                    <el-input type="text" v-model="loginForm.username" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="密码:" prop="password">
                    <el-input type="password" v-model="loginForm.password" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="login()">提交</el-button>
                    <el-button >重置</el-button>
                </el-form-item>
            </el-form>
        </div>
    </div>
</body>
<script>
     var app=new Vue({
           el:"#login",
           data:{
               //登录的表单对象
               loginForm:{username:"admin",password:"123456"},
               //登录的规则
               loginRules:{
                    username:[
                        { required: true, message: '请输入账号', trigger: 'blur' },
                    ],
                    password:[
                        { required: true, message: '请输入密码', trigger: 'blur' },
                    ]
               }
           },
           methods:{
                login(){
                    this.$refs.ruleForm.validate((valid) => {
                        if(valid){
                            axios.post("/login/login",this.loginForm).then(resp=>{
                                  if(resp.data.code===2000){
                                      this.$message.success("登录成功");
                                      location.href="/index.jsp";
                                  }else{
                                      this.$message.error("登录失败");
                                  }
                            })
                        }
                    })
                }
           }
     })
</script>

<style>
      #loginBox{
           width: 450px;
           height: 300px;
           border: 1px solid red;
           margin: 150px auto;

      }
    #loginForm{
          margin: 20px auto;
    }
</style>
</html>
